package com.atguigu.demojuc.chap09;

import com.sun.tools.javac.Main;

/**
 * @author njg
 * @version 1.0
 * @date 2025/6/18 20:03
 */
public class VolatileDemo {
    private volatile static Integer flag = 1;
    public static void main(String[] args) throws InterruptedException {
        new Thread(() -> {
            System.out.println(Thread.currentThread().getName() + "\t" + "我是子线程工作内存flag的值"+flag);
            while (flag == 1){
            }
            System.out.println(Thread.currentThread().getName() + "\t" + "子线程结束.."+flag);

        }, "A").start();

        Thread.sleep(500);
        flag = 2;
        System.out.println(Thread.currentThread().getName() + "\t" + "我是主线程工作内存flag"+flag);

    }
}
